var _createClass = function () {
  function n(t, e) {
    for (var a = 0; a < e.length; a++) {
      var n = e[a];
      n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(t, n.key, n);
    }
  }

  return function (t, e, a) {
    return e && n(t.prototype, e), a && n(t, a), t;
  };
}();

function _classCallCheck(t, e) {
  if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
}

var outwxml = function () {
  function i(t) {
    _classCallCheck(this, i);

    var e = this;

    for (var a in e.config = {}, t = t || {}) e.config[a] = t[a];

    var n = require("./main.js");

    e.m = {
      fs: require("./fs.js"),
      path: require("./path.js"),
      towxml: new n()
    };
  }

  return _createClass(i, [{
    key: "init",
    value: function () {
      var t = this;
      t.outtag();
      var e = t.outwxml();
      t.m.fs.writeFileSync("./renderTemplate.wxml", e);
    }
  }, {
    key: "outtag",
    value: function (n) {
      var i = "",
          r = this.outattr();
      return this.m.towxml.wxmlTag.forEach(function (t, e) {
        var a = "";
        "image" === t && (a = 'mode="widthFix"'), i += "\n                    <" + t + " wx:if=\"{{item.node === 'element' && item.tag === '" + t + "'}}\" " + r + " " + a + '>\n                        <block wx:for="{{item.child}}" wx:key="{{item}}">\n                            <template is="m' + n + '" data="{{item}}"/>\n                        </block>\n                    </' + t + ">\n            ";
      }), i;
    }
  }, {
    key: "outattr",
    value: function () {
      var a = "";
      return ["class", "width", "height", "data", "src", "id", "style"].forEach(function (t, e) {
        a += "class" === t ? t + '="{{item.attr.className}}"' : t + '="{{item.attr.' + t + '}}"';
      }), a;
    }
  }, {
    key: "outwxml",
    value: function () {
      for (var t = "", e = 0, a = this.config.depth; e < a; e++) {
        var n = e < a - 1 ? e + 1 : e;
        t += '<template name="m' + e + '"><block wx:if="{{item.node === \'text\'}}">{{item.text}}</block>' + this.outtag(n) + "</template>";
      }

      return t;
    }
  }]), i;
}();

new outwxml({
  depth: 10
}).init();